#pragma once
#include <lcir/ADT/ListNode.h>
#include <lcir/IR/Value.h>

#include <stdexcept>
#include <variant>
namespace lcir {
class Value;
class Expression;
class Operand final : public NestListNode<Operand, Value> {
  friend class Expression;
  Value *value{nullptr};
  Expression *expr{nullptr};

public:
  Value *getParent() const { return value; };
  Value *getValue() const { return value; }
  Expression *getExpr() const { return expr; }
  void setValue(Value *newValue) { 
     if(value) {
      removeFromParent();
     }
    value=newValue;
    newValue->addUser(this);
  }

private:
  void setExpression(Expression *exprRef) {
    if (expr)
      throw std::runtime_error("can't set operand's expression twice!");
    else
      expr = exprRef;
  }
};
} // namespace lcir